<?php
class Admin_Forms_ChangePasswordForm extends Zend_Form {
	function __construct($option = null) {
		$this->setAction('')
				->setMethod('POST')
				->setAttrib('enctype', 'multipart/form-data')
				->setAttrib('class', 'form-horizontal');
        $password = $this->createElement ( 'password', 'password' );
		$password->addValidator ( 'StringLength', false, array (6,'messages' =>
                                      array(Zend_Validate_StringLength::TOO_SHORT => 'Mật khẩu không được phép ít hơn 6 ký tự')) )
        	     ->setRequired ( true )
        	     ->addValidator(
				        'NotEmpty',
				        true,
				        array('messages' => array('isEmpty' => 'Mật khẩu không được để trống'))
				    )
        	     ->setLabel('Mật khẩu cũ')
        	     ->addFilter('StringTrim');
        $new_password = $this->createElement ( 'password', 'new_password' );
		$new_password->addValidator ( 'StringLength', false, array (6,'messages' =>
                                      array(Zend_Validate_StringLength::TOO_SHORT => 'Mật khẩu không được phép ít hơn 6 ký tự')) )
        	     ->setRequired ( true )
        	     ->addValidator(
				        'NotEmpty',
				        true,
				        array('messages' => array('isEmpty' => 'Mật khẩu không được để trống'))
				    )
        	     ->setLabel('Mật khẩu mới')
        	     ->addFilter('StringTrim')
        	     ->setDescription('Tối thiểu là 6ký tự.
Chỉ sử dụng chữ và số');
        $re_password = $this->createElement ( 'password', 're_password' );
		$re_password->addValidator ( 'StringLength', false, array (6,'messages' =>
                                      array(Zend_Validate_StringLength::TOO_SHORT => 'Mật khẩu không được phép ít hơn 6 ký tự')) )
        	     ->setRequired ( true )
        	     ->addValidator(
				        'NotEmpty',
				        true,
				        array('messages' => array('isEmpty' => 'Mật khẩu không được để trống'))
				    )
        	     ->setLabel('Nhập lại mật khẩu')
        	     ->addFilter('StringTrim');
        	     	     
		$submit = $this->createElement('submit','submit',array ('label' => $option['submit'] ));
		$submit->setAttrib('class', 'btn-large');
		$cancel = $this->createElement('button', 'cancel',array('label'	=> 'Hủy bỏ','class'=>'btn btn-large','onclick'	=> 'windown:location = "' . $option['cancel_link'] . '"'));
		$this->addElement($password);
		$this->addElement($new_password);
		$this->addElement($re_password);
		$this->addElement($submit)
				->addElement($cancel);
		$this->setDecorators(array('FormElements',array('HtmlTag',array('tag'	=> 'div','width'=>'100%')),'form'));
		$this->setElementDecorators(array(
										'ViewHelper',
										'Errors',
										'Description',
										array(	
											array('data'	=> 'HtmlTag'),
											array('tag'		=> 'div','class'	=> 'controls')),
										array('label',
											array('class'	=> 'control-label','requiredSuffix'=>'(*)')),
										array(
											array('row'	=> 'HtmlTag',),
											array('class'=>'control-group ')
										),
									 	array(
								            array('ErrorsDiv' => 'HtmlTag'),
								            array('tag' => 'span', 'placement' => Zend_Form_Decorator_Abstract::APPEND)
		        						)
									)
								);
		$submit->setDecorators(array(
								'ViewHelper',
						       ));
		$cancel->setDecorators(array(
								'ViewHelper',
									)
						       );
		$this->addDisplayGroup(array('submit','cancel'),'action');
		$action = $this->getDisplayGroup('action');
		$action->setDecorators(array(
                'FormElements',
                'Fieldset',
                array('HtmlTag',array('tag'=>'div','class'	=> 'form-actions'))
        ));
	}
}